cd "/Users/dlk265/Library/CloudStorage/Box-Box/Atkinson Survey Project 2024/Science Spending Update/"
use "GK_PNAS_replication_data.dta", clear
svyset [pw=weight]

* FIGURE 1a: Spending Estimate *
label var sci_spend_initial "Estimated % of Budget Allocated to Science Spending"
graph box sci_spend_initial [pw=weight], over(year)  noout hori 
gen sci_spend_gop5 = sci_spend_initial 
replace sci_spend_gop5 = . if gop5 !=1
gen sci_spend_dem5 = sci_spend_initial 
replace sci_spend_dem5 = . if dem5 !=1 
* 2014 *
graph box sci_spend_initial sci_spend_gop5 sci_spend_dem5 [pw=weight] if year == 2014,  noout hori note("")  ///
legend(order(1 "All" 2 "Republicans" 3 "Democrats") pos(6) rows(1)) bar(1,color(black%70)) bar(2,color(maroon%70)) bar(3,color(navy%70))
* 2025 *
graph box sci_spend_initial sci_spend_gop5 sci_spend_dem5 [pw=weight] if year == 2014,  noout hori note("")  ///
legend(order(1 "All" 2 "Republicans" 3 "Democrats") pos(6) rows(1)) bar(1,color(black%100)) bar(2,color(maroon%100)) bar(3,color(navy%100))
* One Box Plot Combined *
graph box sci_spend_initial sci_spend_gop5 sci_spend_dem5 [pw=weight], over(year)  noout hori  ///
legend(order(1 "All" 2 "Republicans" 3 "Democrats") pos(6) rows(1)) bar(1,color(black%70)) bar(2,color(maroon%70)) bar(3,color(navy%70)) ///
bar(4,color(black%100)) bar(5,color(maroon%100)) bar(6,color(navy%100))

* Quantile regressions at the median *
qreg sci_spend_initial i.year [pw=weight]
qreg sci_spend_initial i.year [pw=weight] if gop5 ==1
qreg sci_spend_initial i.year [pw=weight] if dem5 ==1
* Shifts from 2014 to 2025 for both Republicans and Democrats are statistically significant *

* Comparing preferences across the two surveys *
svy:tab sci_spend_future if year == 2014
svy:tab sci_spend_future if year == 2025
gen sci_spend_increase = sci_spend_future
recode sci_spend_increase (2=0) (3=0)
gen y2025 = 0
replace y2025 = 1 if year == 2025
svy:reg sci_spend_increase y2025

* FIGURE 1b: Treatment Effects and Factors Associated with Support for Increased Federal Science Spending *
* Create standardized variables for Science Knowledge and Age to ease substantive interpretation *
sum sciknow_score
gen sciknow_std = ((sciknow_score-r(mean))/r(sd))
label var sciknow_std "Science Knowledge"
sum age
gen age_std = ((age-r(mean))/r(sd))
label var age_std "Age"

svy:mlogit sci_spend_future sci_spend_correction gop5 dem5 college white female age_std  if year == 2014, b(3)
margins, dydx(*) predict(outcome(1)) post
estimates store a
svy:mlogit sci_spend_future sci_spend_correction gop5 dem5 college white female age_std sciknow_std if year == 2025, b(3)
margins, dydx(*) predict(outcome(1)) post
estimates store c

coefplot (a, mcolor(black) ciopts(lcolor(black)) msize(medium)) (c, msymbol(square) mcolor(green) msize(medium) ciopts(lcolor(green))), drop(_cons) legend(order(2 "2014" 4 "2025") pos(6) rows(1)) xline(0) xti("Marginal Effect on Support for Increased Science Spending")

* Testing whether the difference in treatment effects is statistically significant across the two years -- but this does not include science knowledge in 2025 *
mlogit sci_spend_future i.sci_spend_correction##i.year i.gop5##i.year i.dem5##i.year i.college##i.year i.white##i.year i.female##i.year c.age_std##i.year, b(3)
margins, dydx(*) at(year=2014) predict(outcome(1)) post

* Robustness check: Relationships for 2025 look substantively similar with and without including Science Knowledge *
svy:mlogit sci_spend_future sci_spend_correction gop5 dem5 college white female age_std if year == 2025, b(3)
margins, dydx(*) predict(outcome(1)) post
estimates store b
coefplot (a, mcolor(black) ciopts(lcolor(black))) (b,  msymbol(triangle)) (c, msymbol(square) mcolor(green) ciopts(lcolor(green))), drop(_cons) legend(order(2 "2014" 4 "2025" 6 "2025: with Science Knowledge") pos(6) rows(1))

* Robustness check: Does science knowledge "increase" support across the aisle *
svy:mlogit sci_spend_future sci_spend_correction   college white female age_std i.party3##c.sciknow_std if year == 2025, b(3)
margins, dydx(*)
coefplot, drop(_cons)

* FIGURE 1c: Does Partisanship Moderate Treatment Effects? *
use "GK_PNAS_replication_data.dta", clear
* Create standardized variables for Science Knowledge and Age to ease substantive interpretation *
sum sciknow_score
gen sciknow_std = ((sciknow_score-r(mean))/r(sd))
label var sciknow_std "Science Knowledge"
sum age
gen age_std = ((age-r(mean))/r(sd))
label var age_std "Age"
gen counter = _n
gen gop14 = .
gen dem14 =.
gen gop25 = .
gen dem25 = .
gen gopl14 = .
gen gopu14 = .
gen deml14 = .
gen demu14 = .
gen gopl25 = .
gen gopu25 = .
gen deml25 = .
gen demu25 = .

svy:mlogit sci_spend_future i.sci_spend_correction##i.party3  college white female age_std if year == 2014, b(3)
margins, dydx(sci_spend_correction) at(party3=1) predict(outcome(1)) post
replace gop14 = r(table)[1,2] if counter == 1
replace gopl14 = r(table)[5,2] if counter == 1
replace gopu14 = r(table)[6,2] if counter == 1
svy:mlogit sci_spend_future i.sci_spend_correction##i.party3  college white female age_std if year == 2014, b(3)
margins, dydx(sci_spend_correction) at(party3=2) predict(outcome(1)) post
replace dem14 = r(table)[1,2] if counter == 2
replace deml14 = r(table)[5,2] if counter == 2
replace demu14 = r(table)[6,2] if counter == 2
svy:mlogit sci_spend_future i.sci_spend_correction##i.party3  college white female age_std sciknow_score if year == 2025, b(3)
margins, dydx(sci_spend_correction) at(party3=1) predict(outcome(1)) post
replace gop25 = r(table)[1,2] if counter == 3
replace gopl25 = r(table)[5,2] if counter == 3
replace gopu25 = r(table)[6,2] if counter == 3
svy:mlogit sci_spend_future i.sci_spend_correction##i.party3  college white female age_std sciknow_score if year == 2025, b(3)
margins, dydx(sci_spend_correction) at(party3=2) predict(outcome(1)) post
replace dem25 = r(table)[1,2] if counter == 4
replace deml25 = r(table)[5,2] if counter == 4
replace demu25 = r(table)[6,2] if counter == 4

svy:mlogit sci_spend_future i.sci_spend_correction##i.party3  college white female age_std if year == 2014, b(3)
margins, at(sci_spend_correction=(0(1)1) party3=(1(1)2)) predict(outcome(1)) post
replace gop14 = r(table)[1,1] if counter == 5
replace gopl14 = r(table)[5,1] if counter == 5
replace gopu14 = r(table)[6,1] if counter == 5
replace dem14 = r(table)[1,2] if counter == 6
replace deml14 = r(table)[5,2] if counter == 6
replace demu14 = r(table)[6,2] if counter == 6
svy:mlogit sci_spend_future i.sci_spend_correction##i.party3  college white female age_std sciknow_score if year == 2025, b(3)
margins, at(sci_spend_correction=(0(1)1) party3=(1(1)2)) predict(outcome(1)) post
replace gop25 = r(table)[1,1] if counter == 7
replace gopl25 = r(table)[5,1] if counter == 7
replace gopu25 = r(table)[6,1] if counter == 7
replace dem25 = r(table)[1,2] if counter == 8
replace deml25 = r(table)[5,2] if counter == 8
replace demu25 = r(table)[6,2] if counter == 8

svy:mlogit sci_spend_future i.sci_spend_correction##i.party3  college white female age_std if year == 2014, b(3)
margins, at(sci_spend_correction=(0(1)1) party3=(1(1)2)) predict(outcome(1)) post
replace gop14 = r(table)[1,3] if counter == 9
replace gopl14 = r(table)[5,3] if counter == 9
replace gopu14 = r(table)[6,3] if counter == 9
replace dem14 = r(table)[1,4] if counter == 10
replace deml14 = r(table)[5,4] if counter == 10
replace demu14 = r(table)[6,4] if counter == 10
svy:mlogit sci_spend_future i.sci_spend_correction##i.party3  college white female age_std sciknow_score if year == 2025, b(3)
margins, at(sci_spend_correction=(0(1)1) party3=(1(1)2)) predict(outcome(1)) post
replace gop25 = r(table)[1,3] if counter == 11
replace gopl25 = r(table)[5,3] if counter == 11
replace gopu25 = r(table)[6,3] if counter == 11
replace dem25 = r(table)[1,4] if counter == 12
replace deml25 = r(table)[5,4] if counter == 12
replace demu25 = r(table)[6,4] if counter == 12

recode counter (1=.91) (2=.97) (3=1.03) (4=1.09) (5=1.91) (6=1.97) (7=2.03) (8=2.09) (9=2.91) (10=2.97) (11=3.03) (12=3.09)
replace counter = . if counter >4

twoway (scatter gop14 counter, msymbol(circle_hollow) mcolor(maroon%70) msize(medium)) (scatter dem14 counter,  mcolor(navy%70) msymbol(square_hollow) msize(medium)) (scatter gop25 counter, mcolor(maroon%100) msize(medium)) (scatter dem25 counter, msymbol(square) mcolor(navy%100) msize(medium)) (rcap gopl14 gopu14 counter, color(maroon%70)) (rcap deml14 demu14 counter, color(navy%70)) (rcap gopl25 gopu25 counter, color(maroon%70)) (rcap deml25 demu25 counter, color(navy%70)), xscale(range(.5 3.5)) xlabel(1 "Treatment Effect" 2 "Control" 3 "Correct % Treatment") xti("") legend(order(1 "GOP: 2014" 2 "Dem: 2014" 3 "GOP: 2025" 4 "Dem: 2025") pos(6) rows(1)) yline(0) yti("(Change In)" "Prob. Support Science Increase") 

* ROBUSTNESS CHECK: ANALYSES WITHOUT SURVEY WEIGHTS *
use "GK_PNAS_replication_data.dta", clear
* FIGURE 1a:  UNWEIGHTED *
label var sci_spend_initial "Estimated % of Budget Allocated to Science Spending"
graph box sci_spend_initial [pw=weight], over(year)  noout hori 
gen sci_spend_gop5 = sci_spend_initial 
replace sci_spend_gop5 = . if gop5 !=1
gen sci_spend_dem5 = sci_spend_initial 
replace sci_spend_dem5 = . if dem5 !=1 
* 2014 *
graph box sci_spend_initial sci_spend_gop5 sci_spend_dem5  if year == 2014,  noout hori note("")  ///
legend(order(1 "All" 2 "Republicans" 3 "Democrats") pos(6) rows(1)) bar(1,color(black%70)) bar(2,color(maroon%70)) bar(3,color(navy%70))
* 2025 *
graph box sci_spend_initial sci_spend_gop5 sci_spend_dem5  if year == 2014,  noout hori note("")  ///
legend(order(1 "All" 2 "Republicans" 3 "Democrats") pos(6) rows(1)) bar(1,color(black%100)) bar(2,color(maroon%100)) bar(3,color(navy%100))

* Quantile regressions at the median: UNWEIGHTED *
qreg sci_spend_initial i.year 
qreg sci_spend_initial i.year if gop5 ==1
qreg sci_spend_initial i.year if dem5 ==1
* Shifts from 2014 to 2025 for both Republicans and Democrats are statistically significant *

* Comparing preferences across the two surveys: UNWEIGHTED *
tab sci_spend_future if year == 2014
tab sci_spend_future if year == 2025
gen sci_spend_increase = sci_spend_future
recode sci_spend_increase (2=0) (3=0)
gen y2025 = 0
replace y2025 = 1 if year == 2025
reg sci_spend_increase y2025

* FIGURE 1b: UNWEIGHTED *
* Create standardized variables for Science Knowledge and Age to ease substantive interpretation *
sum sciknow_score
gen sciknow_std = ((sciknow_score-r(mean))/r(sd))
label var sciknow_std "Science Knowledge"
sum age
gen age_std = ((age-r(mean))/r(sd))
label var age_std "Age"
mlogit sci_spend_future sci_spend_correction gop5 dem5 college white female age_std  if year == 2014, b(3)
margins, dydx(*) predict(outcome(1)) post
estimates store a
mlogit sci_spend_future sci_spend_correction gop5 dem5 college white female age_std sciknow_std if year == 2025, b(3)
margins, dydx(*) predict(outcome(1)) post
estimates store c
coefplot (a, mcolor(black) ciopts(lcolor(black)) msize(medium)) (c, msymbol(square) mcolor(green) msize(medium) ciopts(lcolor(green))), drop(_cons) legend(order(2 "2014" 4 "2025") pos(6) rows(1)) xline(0) xti("Marginal Effect on Support for Increased Science Spending")

* FIGURE 1c: UNWEIGHTED *
use "GK_PNAS_replication_data.dta", clear
* Create standardized variables for Science Knowledge and Age to ease substantive interpretation *
sum sciknow_score
gen sciknow_std = ((sciknow_score-r(mean))/r(sd))
label var sciknow_std "Science Knowledge"
sum age
gen age_std = ((age-r(mean))/r(sd))
label var age_std "Age"
gen counter = _n
gen gop14 = .
gen dem14 =.
gen gop25 = .
gen dem25 = .
gen gopl14 = .
gen gopu14 = .
gen deml14 = .
gen demu14 = .
gen gopl25 = .
gen gopu25 = .
gen deml25 = .
gen demu25 = .

mlogit sci_spend_future i.sci_spend_correction##i.party3  college white female age_std if year == 2014, b(3)
margins, dydx(sci_spend_correction) at(party3=1) predict(outcome(1)) post
replace gop14 = r(table)[1,2] if counter == 1
replace gopl14 = r(table)[5,2] if counter == 1
replace gopu14 = r(table)[6,2] if counter == 1
mlogit sci_spend_future i.sci_spend_correction##i.party3  college white female age_std if year == 2014, b(3)
margins, dydx(sci_spend_correction) at(party3=2) predict(outcome(1)) post
replace dem14 = r(table)[1,2] if counter == 2
replace deml14 = r(table)[5,2] if counter == 2
replace demu14 = r(table)[6,2] if counter == 2
mlogit sci_spend_future i.sci_spend_correction##i.party3  college white female age_std sciknow_score if year == 2025, b(3)
margins, dydx(sci_spend_correction) at(party3=1) predict(outcome(1)) post
replace gop25 = r(table)[1,2] if counter == 3
replace gopl25 = r(table)[5,2] if counter == 3
replace gopu25 = r(table)[6,2] if counter == 3
mlogit sci_spend_future i.sci_spend_correction##i.party3  college white female age_std sciknow_score if year == 2025, b(3)
margins, dydx(sci_spend_correction) at(party3=2) predict(outcome(1)) post
replace dem25 = r(table)[1,2] if counter == 4
replace deml25 = r(table)[5,2] if counter == 4
replace demu25 = r(table)[6,2] if counter == 4

mlogit sci_spend_future i.sci_spend_correction##i.party3  college white female age_std if year == 2014, b(3)
margins, at(sci_spend_correction=(0(1)1) party3=(1(1)2)) predict(outcome(1)) post
replace gop14 = r(table)[1,1] if counter == 5
replace gopl14 = r(table)[5,1] if counter == 5
replace gopu14 = r(table)[6,1] if counter == 5
replace dem14 = r(table)[1,2] if counter == 6
replace deml14 = r(table)[5,2] if counter == 6
replace demu14 = r(table)[6,2] if counter == 6
mlogit sci_spend_future i.sci_spend_correction##i.party3  college white female age_std sciknow_score if year == 2025, b(3)
margins, at(sci_spend_correction=(0(1)1) party3=(1(1)2)) predict(outcome(1)) post
replace gop25 = r(table)[1,1] if counter == 7
replace gopl25 = r(table)[5,1] if counter == 7
replace gopu25 = r(table)[6,1] if counter == 7
replace dem25 = r(table)[1,2] if counter == 8
replace deml25 = r(table)[5,2] if counter == 8
replace demu25 = r(table)[6,2] if counter == 8

mlogit sci_spend_future i.sci_spend_correction##i.party3  college white female age_std if year == 2014, b(3)
margins, at(sci_spend_correction=(0(1)1) party3=(1(1)2)) predict(outcome(1)) post
replace gop14 = r(table)[1,3] if counter == 9
replace gopl14 = r(table)[5,3] if counter == 9
replace gopu14 = r(table)[6,3] if counter == 9
replace dem14 = r(table)[1,4] if counter == 10
replace deml14 = r(table)[5,4] if counter == 10
replace demu14 = r(table)[6,4] if counter == 10
mlogit sci_spend_future i.sci_spend_correction##i.party3  college white female age_std sciknow_score if year == 2025, b(3)
margins, at(sci_spend_correction=(0(1)1) party3=(1(1)2)) predict(outcome(1)) post
replace gop25 = r(table)[1,3] if counter == 11
replace gopl25 = r(table)[5,3] if counter == 11
replace gopu25 = r(table)[6,3] if counter == 11
replace dem25 = r(table)[1,4] if counter == 12
replace deml25 = r(table)[5,4] if counter == 12
replace demu25 = r(table)[6,4] if counter == 12

recode counter (1=.91) (2=.97) (3=1.03) (4=1.09) (5=1.91) (6=1.97) (7=2.03) (8=2.09) (9=2.91) (10=2.97) (11=3.03) (12=3.09)
replace counter = . if counter >4

twoway (scatter gop14 counter, msymbol(circle_hollow) mcolor(maroon%70) msize(medium)) (scatter dem14 counter,  mcolor(navy%70) msymbol(square_hollow) msize(medium)) (scatter gop25 counter, mcolor(maroon%100) msize(medium)) (scatter dem25 counter, msymbol(square) mcolor(navy%100) msize(medium)) (rcap gopl14 gopu14 counter, color(maroon%70)) (rcap deml14 demu14 counter, color(navy%70)) (rcap gopl25 gopu25 counter, color(maroon%70)) (rcap deml25 demu25 counter, color(navy%70)), xscale(range(.5 3.5)) xlabel(1 "Treatment Effect" 2 "Control" 3 "Correct % Treatment") xti("") legend(order(1 "GOP: 2014" 2 "Dem: 2014" 3 "GOP: 2025" 4 "Dem: 2025") pos(6) rows(1)) yline(0) yti("(Change In)" "Prob. Support Science Increase") 
